//修改目录组件
<template>
  <div class="container">
    <el-form :model="editDirectoryList" :rules="directoryRules" ref="directorysFormRef" label-width="80px" class="demo-ruleForm">
      <el-form-item v-if="!queryVal.id" class="elform" label="所属学科">
        <el-select v-model="editDirectoryList.subjectID" placeholder="请选择" style="width: 100%;">
          <el-option :label="item.label" :value="item.value" v-for="item in selectValue" :key="item.value"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item class="elform" label="目录名称" prop="directoryName">
        <el-input v-model="editDirectoryList.directoryName" placeholder="请输入目录名称" style="width: 100%;"></el-input>
      </el-form-item>
    </el-form>

    <!-- 底部两个按钮 -->
    <div slot="footer" style="text-align:right" class="dialog-footer">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="editDirForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
//调用修改请求
import { update } from '../../api/hmmm/directorys'
export default {
  name: 'directorysEdit',
  data() {
    return {
      // 修改的请求数据
      editDirectoryList: {
        directoryName: this.editclick.directoryName,
        subjectID: this.editclick.subjectID
      },
      //校验规则
      directoryRules: {
        directoryName: { required: true, message: '请输入目录名称', trigger: 'blur' }
      },
      isid: ''
    }
  },
  props: {
    selectValue: {
      type: Array,
      required: true
    },
    editclick: {},
    queryVal: {
      type: Object,
      require: true
    }
  },

  methods: {
    async editDirForm() {
      if (this.queryVal.id) {
        this.editDirectoryList.subjectID = parseInt(this.queryVal.id)
      }
      try {
        await update({
          id: this.editclick.id,
          subjectID: this.editDirectoryList.subjectID,
          directoryName: this.editDirectoryList.directoryName
        })
        this.$message.success('修改目录成功')
        this.$emit('close')
        this.$emit('updatetable')
      } catch (error) {
        console.log(error)

        this.$message.error('修改目录失败')
      }
    }
  }
}
</script>

<style></style>
